﻿@model IEnumerable<FollowPeers.Models.Jobs>
@using FollowPeers.Models;
@Html.Partial("_Header")
@{
    ViewBag.Title = "Jobs";
    FollowPeers.Models.FollowPeersDBEntities followPeersDB = new FollowPeers.Models.FollowPeersDBEntities();
    string name = Membership.GetUser().UserName;
    ViewBag.UserName = name;
    FollowPeers.Models.UserProfile myprofile = followPeersDB.UserProfiles.First(p => p.UserName == name);
    List<FollowPeers.Models.Jobs> UploadedJob = new List<FollowPeers.Models.Jobs>();
    UploadedJob = followPeersDB.Jobs.Where(p => p.ownerID == myprofile.UserProfileId).ToList();
    List<Jobs> Appliedjobs = new List<FollowPeers.Models.Jobs>();
    Appliedjobs = myprofile.AppliedJobs.ToList();
    List<FollowPeers.Models.Favourite> Savedjobs = new List<FollowPeers.Models.Favourite>();
    Savedjobs = followPeersDB.Favourites.Where(p => p.UserProfile.UserProfileId == myprofile.UserProfileId && p.ItemType == 4).ToList();   
}
<div class="container" id="main">
    <div class="row">
@Html.Partial("_SideBar1")
        <div class="span8">
           <ul class="nav nav-tabs" id="myTab"> 
                <li id="li_tab1" class="active" onclick="tab('tab1')"><a>Jobs Home</a></li>
                <li id="li_tab2" onclick="tab('tab2')"><a>Applied Jobs</a></li>
                <li id="li_tab3" onclick="tab('tab3')"><a>Saved Jobs</a></li>
                <li id="li_tab4" onclick="tab('tab4')"><a>Uploaded Jobs</a></li>
            </ul>   
                <div class="tab-content">
                    <div id="tab2" style="display: none;" class="tab-pane" >
                        @{
                            if (Appliedjobs.Count() != 0)
                            {
                            <span class="label label-info">Number of Applied Jobs: @Appliedjobs.Count()</span><br /><br />
                         <table  class="table table-hover">
                        @foreach (var item in Appliedjobs)
                        {
                                <tr><td>       
                                <div style="margin-left: 8px;">
                                    <a href="/Jobs/Details/@item.JobId" id="title"><b>@item.Title</b></a> 
                                </div>
                                <div>
                                    <b>@item.Company    |   @item.Country   |   @item.publishDate</b>
                                </div>
                                </td></tr>                             
                        }
                       </table>
                            }
                            else
                            {
                                <span class="label label-info">Number of Applied Jobs: 0</span><br /><br />
                            <text>You haven't applied to any jobs yet. </text>
                            }
                            }
                    </div>
                    <div id="tab3" style="display: none;" class="tab-pane" >
                    @{List<Jobs> result = myprofile.Jobs.ToList();
                        <span class="label label-info">Number of Saved Jobs: @Savedjobs.Count()</span><br /><br />
                         <table  class="table table-hover">
                        @foreach (var item in result)
                        {
                            if (item.ownerID != myprofile.UserProfileId)
                            {
                                <tr><td>       
                                <div style="margin-left: 8px;">
                                    <a href="/Jobs/Details/@item.JobId" id="title"><b>@item.Title</b></a> 
                                </div>
                                <div>
                                    <b>@item.Company    |   @item.Country   |   @item.publishDate</b>
                                </div>
                                </td></tr>                             
                            }
                        }
                       </table>
                    }
                    </div>
                    <div id="tab4" style="display: none;" class="tab-pane" >
                     @{ 
                         if (UploadedJob.Count() != 0)
                         {
                    <span class="label label-info">Number of Jobs posted: @UploadedJob.Count()</span>
				        <a class="btn btn-primary pull-right" href="@Url.Content("~/Jobs/Create/1")" ><i class="icon-upload icon-white"></i>Add new</a>
                    <br /><br />
                      
                               <table class="table table-hover">
                               @foreach (var item in UploadedJob)
                               {
                                                       
                            <tr><td>       
                            <div style="margin-left: 8px;">
                            <a href="/Jobs/Details/@item.JobId" id="title"><b>@item.Title</b></a> 
                            </div>
                            <div>
                                <b>@item.Company    |   @item.Country   |   @item.publishDate</b>
                </div>
            </td></tr>
                               }
                                 </table>
                         }
                         else
                         {
                               <span class="label label-info">Number of Jobs posted: @UploadedJob.Count()</span>
				        <a class="btn btn-primary pull-right" href="@Url.Content("~/Jobs/Create/1")" ><i class="icon-upload icon-white"></i>Add new</a>
                    <br /><br />
                         <text>You haven't uploaded any jobs yet</text> 
                         }
                         
                        
                           }
                           </div>
                    <div id="tab1" style="display: none; overflow:hidden; padding:0px,0px,0px,0px; margin:0px;" class="tab-pane active" >
                    <div class="span8" style="padding:0px,0px,0px,0px; margin:0px;">
                        <div class="row span7">                          
                            <div class="form-search" >
                                <input type="text" id="keyword_string" class="input-medium search-query span4"  />
                                <a id="Search_Job" class="btn btn-danger">Search</a>&nbsp;&nbsp;
                                <a id="trigger">Advanced Serach</a>
                                <div id="toolWrapper" style="display: none; top: -7px;">
                    <div style="padding: 7px; color: #777; background: #ddd; width: 100%; margin: 3px;">
                        Advanced Job Search</div>
                    <form action="Index" style="padding: 7px;">
                    <div class="editor-label" style="color:blue; font-weight: bold;">
                        Keywords</div>
                    <input id="keywordstring" name="keywords" type="text" name="sort" style="width:250px"/>
                    <div class="editor-label" style="color: blue; font-weight: bold;">
                        Job Title</div>
                        <input type="text" id="jobtitlestring" style="width:250px"/>
                    <div class="editor-label" style="color: blue; font-weight: bold;">
                        Country</div>
                    <div class="editor-field" style="height: auto">
                        @{
                            List<SelectListItem> items = new List<SelectListItem>();
                            foreach (var i in followPeersDB.Countries)
                            {
                                items.Add(new SelectListItem { Text = i.Name, Value = i.Name });
                            }
                            IEnumerable<SelectListItem> list = items.ToArray();
                            @Html.DropDownList("Country", list, new { id = "countrystring", style = "width:257px;" });
                             
                        }
                    </div>
                    <div class="editor-label" style="color:blue; font-weight: bold;">
                        Specialization</div>
                    <div class="editor-field" style="height: auto">
                        @{
                            List<SelectListItem> items2 = new List<SelectListItem>();
                            List<FollowPeers.Models.Specialization> temp = followPeersDB.Specializations.ToList();
                            var newlist = temp.OrderBy(x => x.SpecializationName).ToList();
                            items2.Add(new SelectListItem { Text = "Any Specialization", Value = "Any" });
                            foreach (var i in newlist)
                            {
                                items2.Add(new SelectListItem { Text = i.SpecializationName, Value = i.SpecializationName });
                            }
                            IEnumerable<SelectListItem> list2 = items2.ToArray();
                            @Html.DropDownList("Specialization", list2, new { id = "specialisationstring", style = "width:257px;" });
                             
                        }
                    </div>
                    <input id="AdvanceSearch" class="btn btn-danger span1" style="float:right;" value="Submit" /><br />
                    </form>
                </div>
                            </div>
                        </div>
                        <br />
                        <br />
                       <table  class="table table-hover">
                       @{ if (Model.Count() != 0)
                          {
                              foreach (var item in Model)
                              {
                                       <tr><td>       
                <div style="margin-left: 8px;">
                    <a href="/Jobs/Details/@item.JobId" id="title"><b>@item.Title</b></a> 
                </div>
                <div>
                    <b>@item.Company    |   @item.Country   |   @item.publishDate</b>
                </div>
            </td></tr>
                              }

                          }
                          }
                          </table>
                        </div>
                    </div>
                </div>
                </div>
            </div>
    </div>
@helper Script(string scriptName)
    {
    <script src="@Url.Content("~/Scripts/" + scriptName)" type="text/javascript"></script>
}
<script type="text/javascript">

    function tab(tab) 
    {
        document.getElementById('tab1').style.display = 'none';
        document.getElementById('tab2').style.display = 'none';
        document.getElementById('tab3').style.display = 'none';
        document.getElementById('tab4').style.display = 'none';
        document.getElementById('li_tab1').setAttribute("class", "");
        document.getElementById('li_tab2').setAttribute("class", "");
        document.getElementById('li_tab3').setAttribute("class", "");
        document.getElementById('li_tab4').setAttribute("class", "");
        document.getElementById(tab).style.display = 'block';
        document.getElementById('li_'+ tab).setAttribute("class", "active");
    }

    $(document).ready(function () {
        tab('tab1');
    });

    $(document).ready(function () {

        $("#trigger").click(function () {
            $('#toolWrapper').toggle(function () {
                $(document).click(function (event) {
                    if (!($(event.target).is('#toolWrapper') || $(event.target).parents('#toolWrapper').length || $(event.target).is('#trigger'))) {
                        $('#toolWrapper').hide(500);
                    }
                });
            });
        });
    });
    $("#Search_Job").click(function () {
        // Get publication ID
        var keyword = $("#keyword_string").val();
        // Send Ajax Request
        $.ajax({
            type: "POST",
            url: "/Jobs/SearchTemp",
            data: "ID=" + keyword,
            success: function () {
                var link = "@Url.Action("SearchJob", "Jobs", null)";
                window.location.href=link;
            }
        });
    });
        
    $("#AdvanceSearch").click(function () {
        var keyword_string = $("#keywordstring").val();
        var jobtitle_string = $("#jobtitlestring").val();
        var country_string = $("#countrystring").val();
            $.ajax({
            type: "POST",
            url: "/Jobs/AdvanceTemp",
            data: {id : keyword_string, jobtitle : jobtitle_string, country : country_string},
            success: function () {
                var link = "@Url.Action("AdvanceSearch", "Jobs",null)";
                window.location.href=link;
            }
            });
        });

 </script>

